/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.city.set.eia.cityblog.entities.managedbeans;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import java.util.List;
import java.util.Collection;
import edu.city.set.eia.cityblog.entities.Tag;
import edu.city.set.eia.cityblog.sessionbeans.TagFacadeLocal;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import java.util.ResourceBundle;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;



/**
 *
 * @author user
 */
@ManagedBean
@RequestScoped
public class TagBean {
     private static final ResourceBundle cityblog = ResourceBundle.getBundle("cityblog");
    
    
    List<Tag> tags;
    Tag selectedTag;
    @EJB TagFacadeLocal tagFacade;
    
    /** Creates a new instance of TagBean */
    public TagBean() {
    }
    
    
    
     @PostConstruct
    public void retrieveCustomers(){
      this.setTags(tagFacade.findAll());
    }
    
    public void setTags(List<Tag> tags){
        this.tags = tags;
    }
    public List<Tag> getArticles(){
        return this.tags;
    }

    public void setSelectedTag(Tag selTag){
        this.selectedTag = selTag;
    }
    public Tag getSelectedTag(){
        return this.selectedTag;
    }
    
     public String retrieveSelectedTag(Integer tagId){
        selectedTag = tagFacade.find(tagId);
        return "showTag";
    }
    
    
     public void persistTag(){
        if (selectedTag != null){
            tagFacade.edit(selectedTag);
            FacesContext.getCurrentInstance().addMessage(null, 
                    new FacesMessage(FacesMessage.SEVERITY_INFO, 
                    cityblog.getString("update.message"), cityblog.getString("update.message")));
        }
   
    
    
     }
}